package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazUserRechargeDO;
import com.jinzhi.jzweb.service.JazUserRechargeService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 充值管理
 * </pre>
 * <small> 2023-04-18 09:56:26 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazUserRecharge")
public class JazUserRechargeController extends BaseController {
	@Autowired
	private JazUserRechargeService jazUserRechargeService;

	/**
	 * 充值详情页
	 * */
	@GetMapping("/info")
	String JazUserIntegral(){
		return "jzweb/jazUserRecharge/info";
	}



	@GetMapping()
	@RequiresPermissions("jzweb:jazUserRecharge:jazUserRecharge")
	String JazUserRecharge(){
	    return "jzweb/jazUserRecharge/jazUserRecharge";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:jazUserRecharge:jazUserRecharge")
	public Result<Page<JazUserRechargeDO>> list(JazUserRechargeDO jazUserRechargeDTO){
		// 查询列表数据
		Page<JazUserRechargeDO> page = jazUserRechargeService.selectPage(getPage(JazUserRechargeDO.class),
					jazUserRechargeService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				JazUserRechargeDO obj = (JazUserRechargeDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazUserRecharge:add")
	String add(){
	    return "jzweb/jazUserRecharge/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazUserRecharge:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazUserRechargeDO jazUserRecharge = jazUserRechargeService.selectById(id);
		model.addAttribute("jazUserRecharge", jazUserRecharge);
	    return "jzweb/jazUserRecharge/edit";
	}
	

	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazUserRecharge:add")
	public Result<String> save( JazUserRechargeDO jazUserRecharge){
		jazUserRechargeService.insert(jazUserRecharge);
        return Result.ok();
	}
	

	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazUserRecharge:edit")
	public Result<String>  update( JazUserRechargeDO jazUserRecharge){
		boolean update = jazUserRechargeService.updateById(jazUserRecharge);
		return update ? Result.ok() : Result.fail();
	}
	

	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazUserRecharge:remove")
	public Result<String>  remove( Long id){
		jazUserRechargeService.deleteById(id);
        return Result.ok();
	}
	

	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazUserRecharge:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazUserRechargeService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
